<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="班级编号" prop="classesNumber">
        <el-input
          v-model="queryParams.classesNumber"
          placeholder="请输入班级编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级名称" prop="classesName">
        <el-input
          v-model="queryParams.classesName"
          placeholder="请输入班级名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级代码" prop="classesCode">
        <el-input
          v-model="queryParams.classesCode"
          placeholder="请输入班级代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="开办时间" prop="openingTime">
        <el-date-picker
          v-model="queryParams.openingTime"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          @click="handleAdd"
          v-hasPermi="['collegebase:classes:create']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['collegebase:classes:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain @click="showClock = true"
          >学生考勤</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list" @select="handleSelect">
      <el-table-column
        label="编号"
        align="center"
        v-if="columns[0].visible"
        width="115"
        :show-tooltip-when-overflow="true"
        prop="classesNumber"
      />
      <el-table-column
        label="班级名称"
        align="center"
        :show-tooltip-when-overflow="true"
        v-if="columns[1].visible"
        width="120"
        prop="classesName"
      />
      <el-table-column
        label="班级代码"
        align="center"
        v-if="columns[2].visible"
        :show-tooltip-when-overflow="true"
        width="115"
        prop="classesCode"
      />
      <el-table-column
        label="专业"
        align="center"
        :show-tooltip-when-overflow="true"
        v-if="columns[3].visible"
        width="125"
        prop="professionsName"
        key="3"
      >
        <template slot-scope="scope">
          <!-- <dict-tag :type="DICT_TYPE.CLSSS_PROPERTIES" :value="scope.row.professionId||'暂无'" /> -->
          {{ scope.row.professionsName }}
        </template>
      </el-table-column>
      <el-table-column
        label="培养层次"
        align="center"
        v-if="columns[4].visible"
        :show-tooltip-when-overflow="true"
        width="125"
        prop="hierarchy"
        key="4"
      >
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.STUDENT_TRAINING_LEVEL"
            :value="scope.row.hierarchy"
          /> </template
      ></el-table-column>
      <el-table-column
        label="系部"
        align="center"
        v-if="columns[5].visible"
        width="125"
        prop="departmentsName"
        :show-tooltip-when-overflow="true"
        key="5"
      >
        <template slot-scope="scope">
          {{ scope.row.departmentsName }}
        </template></el-table-column
      >
      <el-table-column
        label="学院"
        align="center"
        v-if="columns[6].visible"
        width="125"
        prop="collegeName"
        :show-tooltip-when-overflow="true"
        key="6"
      >
        <template slot-scope="scope">
          {{ scope.row.collegeName }}
        </template></el-table-column
      >
      <!-- <el-table-column
        label="班主任"
        align="center"
        v-if="columns[7].visible"
        prop="classTeacherName"
      >

        </el-table-column
      >
      <el-table-column
        label="辅导员"
        align="center"
        v-if="columns[8].visible"
        prop="classInstructorName"
      >

      </el-table-column> -->
      <el-table-column
        label="年级"
        align="center"
        v-if="columns[9].visible"
        prop="classesGrade"
        width="135"
      />
      <el-table-column
        label="开班时间"
        align="center"
        v-if="columns[10].visible"
        prop="openingTime"
        width="155"
        key="10"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.openingTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="在班学生"
        align="center"
        v-if="columns[11].visible"
        width="72"
        prop="studentCount"
      >
      </el-table-column>
      <!-- <el-table-column
        label="创建时间"
        align="center"
        v-if="columns[12].visible"
        prop="createTime"
        width="180"
        key="12"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        align="center"
        v-if="columns[13].visible"
        prop="remark"
      /> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="110px"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加修改组件 -->
    <form-edit
      :show.sync="open"
      v-if="open"
      :title="title"
      :classId="classId"
      @success="getList"
      ref="editDialog"
    ></form-edit>
    <!-- 学生考勤 -->
    <clockRecord :show.sync="showClock" />
  </div>
</template>

<script>
import {
  deleteClasses,
  getClassesPage,
  exportClassesExcel,
} from "@/api/teacherSide/classes";
import formEdit from "./formEdit";
import clockRecord from "./clockRecord";

import { mapGetters } from 'vuex';
export default {
  name: "Classes",
  components: {
    formEdit,
    clockRecord
  },
  data() {
    return {
      columns: [
        { key: 0, label: `编号`, visible: true },
        { key: 1, label: `班级名称`, visible: true },
        { key: 2, label: `班级代码`, visible: true },
        { key: 3, label: `专业`, visible: true },
        { key: 4, label: `培养层次`, visible: true },
        { key: 5, label: `系部`, visible: true },
        { key: 6, label: `学院`, visible: true },
        { key: 7, label: `班主任`, visible: true },
        { key: 8, label: `辅导员`, visible: true },
        { key: 9, label: `年级`, visible: true },
        { key: 10, label: `开班时间`, visible: true },
        { key: 11, label: `在班学生`, visible: true },
        { key: 12, label: `创建时间`, visible: false },
        { key: 13, label: `备注`, visible: false },
      ],
      showClock: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学校管理-班级列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeOpeningTime: [],
      classId: undefined,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        classesNumber: null,
        classesName: null,
        classesCode: null,
        // openingTime: [],
        // classesGrade: null,
      },
    };
  },
  computed: {
    ...mapGetters(['userId'])
  },
  created() {
    this.getList();
  },
  methods: {
    handleSelect(select) {
      console.log("已选择数据", select);
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = { ...this.queryParams, teacherId: this.userId };
      // 执行查询
      getClassesPage(params).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total || 0;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeOpeningTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加学校管理-班级";
      this.$refs.editDialog.initData({});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.classId = row.id;
      this.open = true;
      this.title = "查看班级";
      // this.$refs.editDialog.initData(form);

    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal
        .confirm('是否确认删除学校管理-班级编号为"' + id + '"的数据项?')
        .then(function () {
          return deleteClasses(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      // this.addBeginAndEndTime(params, this.dateRangeOpeningTime, "openingTime");
      // 执行导出
      this.$modal
        .confirm("是否确认导出所有学校管理-班级数据项?")
        .then(() => {
          this.exportLoading = true;
          return exportClassesExcel(params);
        })
        .then((response) => {
          this.$download.excel(response, "学校管理-班级.xls");
          this.exportLoading = false;
        })
        .catch(() => { });
    },
  },
};
</script>
